var num = 1;
var pageSize = 10;
var role = "operator";
function listUser(role, pageNum, pageSize) {
    $.ajax({
        url: HOST.concat("/users/role?role=" + role + "&pageNum=" + pageNum + "&pageSize=" + pageSize + "&token=" + config.token),
        type: "GET",
        success: function(datas){
			checkLogin(datas);
        	addContent(datas);
        },
        error: function(){
            console.log("请求用户列表错误！");
        },
        dataType: "json",
    });
}

function addContent(res){
	//查询成功
        if(res.meta.state==="success") {
            var list = res.data;
			if(list.length==0){
				alert("已经是最后一页!");
				num--;
			}else{
				console.log("有查询记录");
				console.log(list);
				$("#tbody").empty();
				$("#pageNum").text(num);
				var count = 0;
				for (var p in list) {
				    var item = list[p];//单条数据
				    count++;
				    var username = item["username"];
				    var createTime = item["createTime"];
				    $("#tbody").append("<div class=\"tr clearfix border-bottom-none\">" +
				        // "                  <div class=\"td w10\"> <input type=\"checkbox\"/></div>" +
				        "                  <div class=\"td w20\">" + count + "</div>" +
				        "                  <div class=\"td w40\">" + username + "</div>" +
				        "                  <div class=\"td w40\">" + createTime + "</div>" +
				        "               </div>");
				}
			}
	        
        }
        //查询失败
        else if(res.meta.message!="notlogin"){
            alert("已经是最后一页!");
            num--;
        }
}

function getUsersList(num){
	listUser(role,num,pageSize);
}

function operatorsLastPage(){
	if(num<=1){
		num = 1;
		alert("已经是第一页!");
		$("#pageNum").text(num);
	}else{
		num--;
		getUsersList(num);
	}
}

function operatorsNextPage(){
		num++;
		getUsersList(num);
}
function operatorsFirstPage(){
	num = 1;
	$("#pageNum").text(num);
	getUsersList(num);
}

getUsersList(1);